home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Sample Code / Snippets / Development Tools & Languages / Windoid / UWindoid.cp < prev    next >
Encoding:
Text File  |  1995-02-13  |  18.3 KB  |  714 lines  |  [TEXT/MPS ]

  1. // UWindoid.cp ------------------------------------------------------------------------
  2. // Copyright © 1991 by Apple Computer, Inc. All rights reserved.
  3.  
  4. #pragma once
  5.  
  6. //-------------------------------------------------------------------------------------
  7. // INCLUDES
  8.  
  9. #include "WindoidRez.h"                                        // combined header file for resource IDs
  10. #include "UWindoid.h"                                        // class definitions
  11.  
  12.  
  13. //-------------------------------------------------------------------------------------
  14. // MEMBER FUNCTIONS
  15.  
  16.  
  17. // TWINDOIDAPPLICATION ----------------------------------------------------------------
  18. #undef Inherited
  19. #define Inherited TApplication
  20.  
  21. #pragma segment AInit
  22. DefineClass(TWindoidApplication, TApplication);
  23.  
  24. #pragma segment AInit
  25.      void TWindoidApplication::IWindoidApplication(OSType itsMainFileType, OSType itsCreator)
  26. {
  27.     Inherited::IApplication(itsMainFileType, itsCreator);
  28.  
  29.     // So my view will be substituted when MacApp® creates the "default view"
  30.     RegisterStdType("TDefaultView", 'dflt');
  31.  
  32.     // so the linker doesn't dead strip class info 
  33.     macroDontDeadStrip(TDefaultView);
  34.     macroDontDeadStrip(TFloatingMenu);
  35.     macroDontDeadStrip(TLightPalette);
  36.     macroDontDeadStrip(TWindow);
  37.  
  38.     // create the floating palette window
  39.     gFloatMenuWindow = (TWindow *)gViewServer->NewTemplateWindow(kLightPaletteRSRCID, NULL);
  40.     FailNIL(gFloatMenuWindow);
  41.     
  42.     // create the floating tool menu
  43.     gFloatingMenu = new TFloatingMenu;                        
  44.     gFloatingMenu->IFloatingMenu();
  45. }
  46.  
  47.  
  48. #pragma segment AInit
  49.      void TWindoidApplication::DoSetupMenus()
  50. {
  51.     Inherited::DoSetupMenus();
  52.     Enable(cGreen,TRUE);
  53.     Enable(cYellow, TRUE);
  54.     Enable(cRed, TRUE);
  55. }
  56.  
  57.  
  58. #pragma segment AOpen
  59.      TDocument* TWindoidApplication::DoMakeDocument(CommandNumber /* itsCommandNumber */,
  60.                                                       TFile*    /* itsFile */)
  61. {
  62.     TWindoidDocument* aWindoidDocument = new TWindoidDocument;
  63.     aWindoidDocument->IDocument();
  64.     return aWindoidDocument;
  65. }
  66.  
  67.  
  68. // TWINDOIDDOCUMENT METHODS -----------------------------------------------------------
  69. #undef Inherited
  70. #define Inherited TDocument
  71.  
  72. #pragma segment AInit
  73. DefineClass(TWindoidDocument, TDocument);
  74.  
  75.      void TWindoidDocument::DoSetupMenus()                // setup document related menus
  76. {
  77.     Inherited::DoSetupMenus();                                // default menus
  78.     Enable(cNormGreen,TRUE);                                // normal traffic light menu entries
  79.     Enable(cNormYellow,TRUE);
  80.     Enable(cNormRed,TRUE);
  81. }
  82.  
  83.  
  84. #pragma segment ASelCommand
  85.      void TWindoidDocument::DoMenuCommand(CommandNumber aCommandNumber)
  86. {
  87.     TCommand* cmdToPost = NULL;
  88.     
  89.     switch(aCommandNumber){
  90.         case cNormGreen:
  91.                        {
  92.                             TGreenCommand *aGreenCommand = new TGreenCommand;
  93.                             aGreenCommand->IGreenCommand(this);
  94.                             cmdToPost = aGreenCommand;
  95.                             break;
  96.                         }
  97.         case cNormYellow:
  98.                         {
  99.                             TYellowCommand *aYellowCommand = new TYellowCommand;
  100.                             aYellowCommand->IYellowCommand(this);
  101.                             cmdToPost = aYellowCommand;
  102.                             break;
  103.                         }
  104.         case cNormRed:
  105.                         {
  106.                             TRedCommand *aRedCommand = new TRedCommand;
  107.                             aRedCommand->IRedCommand(this);
  108.                             cmdToPost = aRedCommand;
  109.                             break;
  110.                         }
  111.         default:
  112.                             Inherited::DoMenuCommand(aCommandNumber);
  113.                             break;
  114.     }
  115.     
  116.     if(cmdToPost != NULL) this->PostCommand(cmdToPost);        // post command
  117. }
  118.  
  119.  
  120. #pragma segment AOpen
  121.      void TWindoidDocument::DoMakeViews(Boolean /*forPrinting*/)
  122. {
  123.     TWindow*            aWindow;
  124.     TDefaultView*        aView;
  125.     FailInfo            fi;
  126.     
  127.     Try(fi) {                                            // start
  128.         aWindow = gViewServer->NewTemplateWindow(kDefaultWindowID, this);    
  129.                                                             // create the window
  130.  
  131.         aView   = (TDefaultView *)aWindow->FindSubView('DFLT');    // get the only view
  132.         FailNIL(aView);                                        // test
  133.         fView = aView;                                        // store in object
  134.         
  135.         fi.Success();                                        // OK
  136.     } 
  137.     else {                                                    // problems
  138.         fi.ReSignal();                                        // signal about it
  139.     }
  140. }
  141.  
  142.  
  143. #pragma segment ADoCommand
  144.      void TWindoidDocument::DoLight(eLights theLight)        // call view method
  145. {
  146.     if(theLight == kGreen)
  147.         fView->DrawGreen();                                    
  148.     else if(theLight == kYellow)
  149.         fView->DrawYellow();                                
  150.     else if(theLight == kRed)
  151.         fView->DrawRed();
  152. }
  153.  
  154.  
  155. // TDEFAULTVIEW METHODS -----------------------------------------------------------------------
  156. #undef Inherited
  157. #define Inherited TView
  158.  
  159. #pragma segment AOpen
  160. DefineClass(TDefaultView, TView);
  161.  
  162.  
  163. TDefaultView::TDefaultView()
  164.  
  165. {
  166.     SetRect(fTrafficRect,kleft, ktop, kright, kbottom);        // initialize various fields
  167.     SetRect(fBlackTopRect, kleft, ktop, kright, ktop + 5);
  168.     SetRect(fTrafficLightFrame,kleft+1, ktop+1, kright+1, kbottom+1);
  169.  
  170.     short xvar = (kright -kleft)/5;                            // define the traffic lights 
  171.     short yvar = (kbottom -ktop)/13;                        // proportional to the view
  172.     
  173.     SetRect(fGreenRect, kleft + xvar, ktop + yvar,            // create rects
  174.                         kleft + (4 * xvar), ktop + (4 * yvar));
  175.     SetRect(fYellowRect,kleft + xvar, ktop + (5 * yvar),
  176.                         kleft + (4 * xvar), ktop + (8 * yvar));
  177.     SetRect(fRedRect,    kleft + xvar, ktop + (9 * yvar),
  178.                         kleft + (4 * xvar), ktop + (12 * yvar));
  179.     
  180.     this->fTitle = "Windoid example:";                        // title
  181.  
  182.     this->fCurrentLight = kGreen;                            // start with green
  183.     
  184. }
  185.  
  186.  
  187. #pragma segment Main
  188.      void TDefaultView::Draw(const VRect&)                  // draw our Traffic Light here
  189. {
  190.     if (GetGrafPort());
  191.  
  192.     this->DrawTrafficLight();                                // draw the object(s)
  193.     this->DrawLight();                                        // testing, temp thing
  194. }
  195.  
  196.  
  197. #pragma segment Main
  198.      void TDefaultView::DrawTrafficLight()                // draw the body
  199. {
  200.     PenNormal();                                                
  201.     PenSize(8, 8);
  202.     PenPat(&qd.black);
  203.     FrameRect(fTrafficRect);                                // draw a dark gray frame
  204.     FrameRect(fBlackTopRect);                                // fill top
  205.  
  206.     PenSize(2,2);                                            // frame traffic lights
  207.     FrameRect(fGreenRect);
  208.     FrameRect(fYellowRect);
  209.     FrameRect(fRedRect);
  210.     
  211.     // Set font and size for subsequent display in the window
  212.     TextFont(geneva);                                        // a nice outline font
  213.     TextSize(9);
  214.     MoveTo(20, 20);
  215.     DrawString(fTitle);                                        // draw the title
  216.     PenNormal();                                            // restore the pen state
  217. }
  218.  
  219.  
  220. #pragma segment Main
  221.      void TDefaultView::DrawLight()                        // select light to draw
  222. {
  223.         if(this->fCurrentLight == kGreen)
  224.             this->DrawGreen();
  225.         else if (this->fCurrentLight == kYellow)
  226.             this->DrawYellow();
  227.         else if (this->fCurrentLight == kRed)
  228.             this->DrawRed();
  229. }
  230.  
  231.  
  232. #pragma segment Main
  233.      void TDefaultView::DrawGreen()                        // draw green light
  234. {
  235.     if( this->Focus() ){
  236.         this->fCurrentLight= kGreen;
  237.         PenNormal();
  238.         ForeColor(whiteColor);
  239.         PaintOval(fYellowRect);
  240.         PaintOval(fRedRect);
  241.     
  242.         ForeColor(greenColor);
  243.         PaintOval(fGreenRect);
  244.         PenNormal();
  245.         ForeColor(blackColor);
  246.     }
  247. }
  248.  
  249.  
  250. #pragma segment Main
  251.      void TDefaultView::DrawYellow()                        // draw yellow light
  252. {
  253.     if( this->Focus() ){
  254.         this->fCurrentLight= kYellow;
  255.         PenNormal();
  256.         ForeColor(whiteColor);
  257.         PaintOval(fGreenRect);
  258.         PaintOval(fRedRect);
  259.     
  260.         ForeColor(yellowColor);
  261.         PaintOval(fYellowRect);
  262.         PenNormal();
  263.         ForeColor(blackColor);
  264.     }
  265. }
  266.  
  267.  
  268. #pragma segment Main
  269.      void TDefaultView::DrawRed()                            // draw red light
  270. {
  271.     if( this->Focus() ){
  272.         this->fCurrentLight= kRed;
  273.         PenNormal();
  274.         ForeColor(whiteColor);
  275.         PaintOval(fYellowRect);
  276.         PaintOval(fGreenRect);
  277.     
  278.         ForeColor(redColor);
  279.         PaintOval(fRedRect);
  280.         PenNormal();
  281.         ForeColor(blackColor);
  282.     }
  283. }
  284.  
  285.  
  286.  
  287.  
  288. // TOOLSELECTCOMMAND METHODS --------------------------------------------------------------
  289.  
  290. #undef Inherited
  291. #define Inherited TTearOffMenuViewTracker
  292.  
  293. #pragma segment ASelCommand
  294. DefineClass(TToolSelectCommand, TTearOffMenuViewTracker);
  295.  
  296.      void TToolSelectCommand::IToolSelectCommand (TLightPalette* theToolsPalette,
  297.                                                      TLightPalette* theMenuToolsPalette,
  298.                                                     TLightPalette* theFloatingToolsPalette,
  299.                                                     VPoint& theMouse)
  300. {
  301.     ITearOffMenuViewTracker(cChangeTool, NULL, kCantUndo, kDoesNotCauseChange,
  302.                             NULL, theToolsPalette, NULL, theMouse);
  303.  
  304.     this->fCausesChange         = FALSE;                    // don't mark the document as changed yet
  305.     this->fTool                    = kNoTool;                    // no tool assigned yet
  306.     this->fExitTracking            = FALSE;                    // no tracking yet
  307.     this->fMenuToolsPalette     = theMenuToolsPalette;        // keep track of the menu views
  308.     this->fFloatingToolsPalette = theFloatingToolsPalette;    // as well as the Floating Window view
  309.     this->fViewConstrain        = FALSE;                    // don't constrain mouse to view limits
  310. }
  311.  
  312.  
  313. #pragma segment ADoCommand
  314.      void TToolSelectCommand::DoIt(void)
  315. {
  316.     // tell the TLightPalette in the menu which tool is selected
  317.     if(fMenuToolsPalette != NULL){
  318.         fMenuToolsPalette->fOldTool = fMenuToolsPalette->fCurrentTool;
  319.         fMenuToolsPalette->fCurrentTool = fTool;
  320.     }
  321.     
  322.     // tell the TLightPalette in the floating window which tool is selected
  323.     if(fFloatingToolsPalette != NULL){
  324.         fFloatingToolsPalette->fOldTool = fFloatingToolsPalette->fCurrentTool;
  325.         fFloatingToolsPalette->SelectNewTool(fTool);
  326.     }
  327.         
  328.     switch(fTool){    // Now post the Menu command which is transformed to a TCommmand inside TDocument
  329.  
  330.         case kGreen:
  331.                     gApplication->GetTarget()->HandleMenuCommand(cNormGreen);
  332.                     break;
  333.         case kYellow:
  334.                     gApplication->GetTarget()->HandleMenuCommand(cNormYellow);
  335.                     break;
  336.         case kRed:
  337.                     gApplication->GetTarget()->HandleMenuCommand(cNormRed);
  338.                     break;
  339.         case kNoTool:
  340.                     break;
  341.         default:
  342.                     break;
  343.     }
  344. }
  345.  
  346.  
  347. #pragma segment ADoCommand
  348.      Boolean TToolSelectCommand::IsDoneTracking(void)
  349. {
  350.     if(!StillDown() || this->fExitTracking)
  351.         return TRUE;
  352.     else
  353.         return FALSE;
  354. }
  355.  
  356.  
  357. #pragma segment ADoCommand
  358.      void    TToolSelectCommand::TrackFeedback  (TrackPhase         aTrackPhase,
  359.                                                 const VPoint&    anchorPoint,
  360.                                                 const VPoint&    previousPoint,
  361.                                                 const VPoint&    nextPoint,
  362.                                                 Boolean            mouseDidMove,
  363.                                                 Boolean            turnItOn)
  364. {    // give us some feedback, and react to it
  365.     if( (fView != NULL) && (fView->IsShown()) && (mouseDidMove) )
  366.         fView->TrackFeedback(aTrackPhase, anchorPoint,previousPoint, nextPoint,
  367.                                 mouseDidMove, turnItOn);
  368.  
  369.     if(turnItOn){
  370.         if(fView == (TView *)fMenuToolsPalette)                // we have a menu tool view
  371.             fTool = fMenuToolsPalette->fSelectedTool;
  372.         if(fView == (TView *)fFloatingToolsPalette)            // we have a floating tool view
  373.             fTool = fFloatingToolsPalette->fSelectedTool;
  374.     }
  375. }
  376.  
  377.  
  378. #pragma segment ASelCommand
  379.      TTracker* TToolSelectCommand::TrackMouse(TrackPhase         aTrackPhase,
  380.                                                 VPoint&            /*anchorPoint */,
  381.                                                 VPoint&            /*previousPoint*/,
  382.                                                 VPoint&            nextPoint,
  383.                                                 Boolean            /*mouseDidMove*/)
  384. {
  385.     if(gTrackingInMenu){
  386.         if( (fView != NULL) && (fView->IsShown()) )
  387.             this->fExitTracking = !fView->ContainsMouse(nextPoint);
  388.             
  389.         if( (aTrackPhase == trackRelease) && (fExitTracking) )
  390.             return NULL;                                    // no tracker needed
  391.     }
  392.     return this;                                            // default behaviour, return tracker
  393. }
  394.  
  395.  
  396. // TTrafficCommand METHODS --------------------------------------------------------------------
  397.  
  398. #undef Inherited
  399. #define Inherited TCommand
  400.  
  401. #pragma segment AInit
  402. DefineClass(TTrafficCommand, TCommand);
  403.  
  404.  
  405. TTrafficCommand::TTrafficCommand()
  406.  
  407. {
  408.  
  409.  
  410. }
  411.  
  412.  
  413. // TGREENCOMMAND METHODS ---------------------------------------------------------------------
  414. #undef Inherited
  415. #define Inherited TTrafficCommand
  416.  
  417. #pragma segment AInit
  418. DefineClass(TGreenCommand, TTrafficCommand);
  419.  
  420.      void TGreenCommand::IGreenCommand(TWindoidDocument* itsDocument)
  421. {
  422.     fCommandDocument = itsDocument;                            // keep track of the document
  423.     Inherited::ICommand(cNormGreen,itsDocument, FALSE, FALSE, NULL);
  424. }
  425.  
  426.  
  427. #pragma segment ADoCommand
  428.      void TGreenCommand::DoIt()
  429. {
  430.     fCommandDocument->DoLight(kGreen);                        // send message to document
  431.     Inherited::DoIt();
  432. }
  433.  
  434.  
  435. // TYELLOWCOMMAND METHODS --------------------------------------------------------------------
  436. #undef Inherited
  437. #define Inherited TTrafficCommand
  438.  
  439. #pragma segment AInit
  440. DefineClass(TYellowCommand, TTrafficCommand);
  441.  
  442.      void TYellowCommand::IYellowCommand(TWindoidDocument* itsDocument)
  443. {
  444.     fCommandDocument = itsDocument;                            // keep track of the document
  445.     Inherited::ICommand(cNormYellow,itsDocument,FALSE, FALSE, NULL);
  446. }
  447.  
  448.  
  449. #pragma segment ADoCommand
  450.      void TYellowCommand::DoIt()
  451. {
  452.     fCommandDocument->DoLight(kYellow);                        // send message to document
  453.     Inherited::DoIt();
  454. }
  455.  
  456.  
  457. // TREDCOMMAND METHODS -----------------------------------------------------------------------
  458. #undef Inherited
  459. #define Inherited TTrafficCommand
  460.  
  461. #pragma segment AInit
  462. DefineClass(TRedCommand, TTrafficCommand);
  463.  
  464.      void TRedCommand::IRedCommand(TWindoidDocument* itsDocument)
  465. {
  466.     fCommandDocument = itsDocument;                            // keep track of the document
  467.     Inherited::ICommand(cNormRed,itsDocument,FALSE, FALSE,NULL);
  468. }
  469.  
  470.  
  471. #pragma segment ADoCommand
  472.      void TRedCommand::DoIt()
  473. {
  474.     fCommandDocument->DoLight(kRed);                        // send message to document
  475.     Inherited::DoIt();
  476. }
  477.  
  478.  
  479. // TFLOATINGMENU METHODS --------------------------------------------------------------------
  480.  
  481. #undef Inherited
  482. #define Inherited TTearOffMenuView
  483.  
  484. #pragma segment ARes
  485. DefineClass(TFloatingMenu, TTearOffMenuView);
  486.  
  487.      void TFloatingMenu::IFloatingMenu() 
  488. {
  489.     TLightPalette* aLightPalette;
  490.  
  491.     ITearOffMenuView(mWindoid, kLightPaletteWidth, kLightPaletteHeight, 
  492.                         (TWindow *)gFloatMenuWindow);
  493.     
  494.     aLightPalette = new TLightPalette;
  495.     aLightPalette->ILightPalette(NULL, this);                
  496.     aLightPalette->fIdentifier = 'MTUL';
  497. }
  498.  
  499.  
  500.  
  501. // TLIGHTPALETTE METHODS --------------------------------------------------------------------
  502.  
  503. #undef Inherited
  504. #define Inherited TView
  505.  
  506. #pragma segment AInit
  507. DefineClass(TLightPalette, TView);
  508.  
  509. TLightPalette::TLightPalette()
  510.  
  511. {
  512.       fCurrentTool         = kNoTool;                            // default settings
  513.     fOldTool             = kNoTool;
  514.     fSelectedTool        = kNoTool;
  515.     fCurrentTool        = kNoTool;
  516.     
  517.     this->BuildChoiceArray();                                // build Rect array
  518.  
  519. }
  520.  
  521.  
  522. #pragma segment AInit
  523.  
  524. void TLightPalette::ILightPalette(TDocument* itsDocument, TView* itsSuperView)
  525. {
  526.     
  527.     VPoint itsSize(kLightPaletteWidth, kLightPaletteHeight);
  528.     this->IView(itsDocument, itsSuperView, gZeroVPt, itsSize, sizeFixed, sizeFixed);
  529.  
  530.     fCurrentTool  = kNoTool;                                // default settings
  531.     fOldTool      = kNoTool;                                // for all the
  532.     fSelectedTool = kNoTool;                                // tool selection fields
  533.  
  534.     this->BuildChoiceArray();                                // build Rects for use in Windoid
  535. }
  536.  
  537.  
  538.  
  539. #pragma segment Main
  540.      void TLightPalette::Draw(const VRect& area)            // draw palette view contents
  541. {
  542.     CRect r;
  543.     register long i;
  544.  
  545.     PenNormal();    
  546.     PenSize(1,1);
  547.     MoveTo((short)fSize.h - 1, 0);                            // make a right side drop effect
  548.     Line(0, (short)fSize.v);                        
  549.  
  550.     for(i = 0; i <= kLightsInPalette; i++){                    // frame rects
  551.         r = fChoiceArray[i];
  552.         FrameRect(r);
  553.  
  554.     }
  555.     
  556.     for(i = 0; i <= kLightsInPalette; i++){
  557.         if(i == kGreen){                                    // first rect == Green
  558.             SetRect(r,5,5,30,30);                            // define the rect
  559.             ForeColor(greenColor);                            // specify green
  560.             PaintOval(r);                                    // paint green oval
  561.             ForeColor(blackColor);                            // set back to black
  562.         }
  563.         else if(i == kYellow){                                // second rect == Yellow        
  564.             OffsetRect(r,0,33);                                // offset a little bit
  565.             ForeColor(yellowColor);                            // specify yellow
  566.             PaintOval(r);                                    // paint yellow oval    
  567.             ForeColor(blackColor);                            // set back to black
  568.         }
  569.         else if(i == kRed){                                    // third rect = Red
  570.             OffsetRect(r,0,33);                                // offset a little bit
  571.             ForeColor(redColor);                            // specify red
  572.             PaintOval(r);                                    // paint red oval
  573.             ForeColor(blackColor);                            // set back to black
  574.         }
  575.     }                                                        // end for loop
  576.         
  577.     PenNormal();
  578.     Inherited::Draw(area);
  579. }
  580.  
  581.  
  582. #pragma segment AInit
  583.      void TLightPalette::BuildChoiceArray()                // build rect array
  584. {
  585.     short top;
  586.     register long i;
  587.     CRect r;
  588.     
  589.     top = 0;
  590.     for (i =0; i < kLightsInPalette; i++){
  591.         SetRect(r,0, top, kLightPaletteWidth - 1, top + kLightPaletteWidth - 1);
  592.         fChoiceArray[i] = r;
  593.         top = top + kLightPaletteWidth - 1;
  594.     }
  595. }
  596.  
  597.  
  598. #pragma segment ARes
  599.      void TLightPalette::Activate(Boolean entering)
  600. {
  601.     if(!entering)                                            // first time in this view?
  602.         fCurrentTool = kNoTool;                                // default setting
  603.     Inherited::Activate(entering);                            // do the rest, TView :: Activate..
  604. }
  605.  
  606.  
  607.  
  608. #pragma segment ASelCommand
  609.      void  TLightPalette::DoMouseCommand(VPoint& theMouse, TToolboxEvent* /*event*/,
  610.                                             CPoint /*hysteresis*/)
  611. {
  612.     TLightPalette*         aMenuLightPalette;
  613.     TLightPalette*        aFloatingLightPalette;
  614.     TToolSelectCommand*    aToolSelectCommand;
  615.  
  616.     aMenuLightPalette = (TLightPalette *)gFloatingMenu->FindSubView('MTUL');    
  617.     
  618.     aFloatingLightPalette = NULL;
  619.     Boolean temp = gFloatMenuWindow->IsShown();
  620.     
  621.     if( gFloatMenuWindow != NULL ){                            // exists
  622.         aFloatingLightPalette =  (TLightPalette *)gFloatMenuWindow->FindSubView('TPLT');
  623.         FailNIL(aFloatingLightPalette);
  624.     }
  625.     
  626.      aToolSelectCommand = new TToolSelectCommand;            // create a tool selection command
  627.     
  628.     aToolSelectCommand->IToolSelectCommand(this, aMenuLightPalette, 
  629.                                                 aFloatingLightPalette, theMouse);
  630.  
  631.     PostCommand(aToolSelectCommand);                        // post the tool select command    
  632. }
  633.  
  634.  
  635. #pragma segment ASelCommand
  636.      void TLightPalette::DoHighlightSelection(HLState /*fromHL*/, HLState toHL)
  637. {
  638.     if( (fCurrentTool != kNoTool) && (fCurrentTool < kLightsInPalette) ){     // valid selection        
  639.         if(toHL == hlOn)                                    // turn on selected tool
  640.             this->Toggle();                
  641.         
  642.         if(toHL == hlOff)                                    // turn off selected tool
  643.                 this->Toggle();                                // turn it off
  644.     }                                                         
  645. }
  646.  
  647.  
  648. #pragma segment ASelCommand
  649.      void TLightPalette::Toggle(void)                        // toggle between tool rects
  650. {
  651.     CRect r;
  652.     
  653.         r = fChoiceArray[fCurrentTool];                        // get the tool
  654.         UseSelectionColor();                                // hilite with the selected color
  655.         InvertRect(r);                                        // invert
  656. }
  657.  
  658.  
  659. #pragma segment ASelCommand
  660.      void TLightPalette::FrameTool(CRect r)                // frame selected tool rect
  661. {
  662.     PenNormal();
  663.     PenMode(patXor);
  664.     PenSize(2,2);
  665.     FrameRect(r);
  666. }
  667.  
  668.  
  669. #pragma segment ASelCommand
  670.      void TLightPalette::SelectNewTool(eLights whichTool)
  671. {
  672.     Boolean foo =this->IsShown();
  673.     
  674.     if( this->IsShown() ){                                    // check if valid floating window
  675.         if( this->Focus() ){
  676.             this->DoHighlightSelection(hlOn,hlOff);            // turn current selection off
  677.             fCurrentTool = whichTool;                        // define new current tool
  678.             this->DoHighlightSelection(hlOff,hlOn);            // turn new selection on
  679.         }
  680.     }
  681. }
  682.  
  683.  
  684. #pragma segment ASelCommand
  685.      void TLightPalette::TrackFeedback(    TrackPhase         /*aTrackPhase*/,
  686.                                             const VPoint&    /*anchorPoint*/,
  687.                                             const VPoint&    /*previousPoint*/,
  688.                                             const VPoint&    nextPoint,
  689.                                             Boolean            mouseDidMove,
  690.                                             Boolean            turnItOn)
  691. {
  692.     CPoint             aPnt;
  693.     CRect             r;
  694.     register long     i;
  695.     
  696.     if(mouseDidMove){
  697.         if( this->Focus() ){
  698.             aPnt = ViewToQDPt(nextPoint);
  699.             for(i = 0; i < kLightsInPalette; i++){            // iterate
  700.                 r = fChoiceArray[i];
  701.                     if( PtInRect(aPnt,r) ){
  702.                         this->FrameTool(r);                    // frame selected tool
  703.                         if(turnItOn)
  704.                             fSelectedTool = (eLights)i;        // the tool selected
  705.                         else
  706.                             fSelectedTool =(eLights)kNoTool;// no tool selected
  707.                     }
  708.             }
  709.         }
  710.     }
  711. }
  712.  
  713.  
  714.